package com.dingreading.cloud.mall.controller;

import com.dingreading.cloud.common.base.R;
import com.dingreading.cloud.common.util.PageUtil;
import com.dingreading.cloud.mall.service.OrderFormServiceV5;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping(value = "/front/orderForm/v3")
@Api(tags = "商城-商城订单管理v5")
public class FrontOrderFormControllerV5 {


    @Resource
    protected OrderFormServiceV5 orderFormServiceV5;


    @ApiOperation(value = "分页列表")
    @PostMapping(value = "/pageList", produces = "application/json; charset=UTF-8")
    public R<Object> pageList(
            @ApiParam(value = "公司uid") @RequestParam(value = "corpUid") String corpUid,
            @ApiParam(value = "门店uid") @RequestParam(value = "storeUid") String storeUid,
            @ApiParam(value = "门店名称") @RequestParam(value = "storeName") String storeName,
            @ApiParam(value = "员工uid") @RequestParam(value = "staffUid") String staffUid,
            @ApiParam(value = "员工名") @RequestParam(value = "staffName") String staffName,
            @ApiParam(value = "分页公共类") PageUtil pageUtil,
            @RequestParam(value = "keyword", required = false) @ApiParam(value = "订单号/用户姓名/手机号") String keyword,
            @RequestParam(value = "status", required = false) @ApiParam(value = "状态 0.取消 1.完成 2.待确认 3.待付款 4.待发货") Integer status
    ) {
        return orderFormServiceV5.pageList(pageUtil, storeUid, staffUid, keyword, status);
    }


    @ApiOperation(value = "获取订单详情")
    @PostMapping(value = "/get", produces = "application/json; charset=UTF-8")
    public R<Object> get(
            @ApiParam(value = "公司uid") @RequestParam(value = "corpUid") String corpUid,
            @ApiParam(value = "门店uid") @RequestParam(value = "storeUid") String storeUid,
            @ApiParam(value = "门店名称") @RequestParam(value = "storeName") String storeName,
            @ApiParam(value = "员工uid") @RequestParam(value = "staffUid") String staffUid,
            @ApiParam(value = "员工名") @RequestParam(value = "staffName") String staffName,
            @ApiParam(value = "订单号") @RequestParam(value = "code") String code
    ) {
        return orderFormServiceV5.get(storeUid, staffUid, code);
    }


    @ApiOperation(value = "获取订单的状态 ,返回4支付成功")
    @PostMapping(value = "/getFormStatus", produces = "application/json; charset=UTF-8")
    public R<Object> getFormStatus(
            @ApiParam(value = "公司uid") @RequestParam(value = "corpUid") String corpUid,
            @ApiParam(value = "门店uid") @RequestParam(value = "storeUid") String storeUid,
            @ApiParam(value = "门店名称") @RequestParam(value = "storeName") String storeName,
            @ApiParam(value = "员工uid") @RequestParam(value = "staffUid") String staffUid,
            @ApiParam(value = "员工名") @RequestParam(value = "staffName") String staffName,
            @ApiParam(value = "订单号") @RequestParam(value = "code") String code
    ) {
        return orderFormServiceV5.getFormStatus(staffUid, code);
    }


    @ApiOperation(value = "判断能否取消订单")
    @PostMapping(value = "/judgeCancel", produces = "application/json; charset=UTF-8")
    public R<Object> judgeCancel(
            @ApiParam(value = "公司uid") @RequestParam(value = "corpUid") String corpUid,
            @ApiParam(value = "门店uid") @RequestParam(value = "storeUid") String storeUid,
            @ApiParam(value = "门店名称") @RequestParam(value = "storeName") String storeName,
            @ApiParam(value = "员工uid") @RequestParam(value = "staffUid") String staffUid,
            @ApiParam(value = "员工名") @RequestParam(value = "staffName") String staffName,
            @ApiParam(value = "订单号") @RequestParam(value = "code") String code
    ) {
        return orderFormServiceV5.judgeCancel(storeUid, staffUid, code);
    }


    @ApiOperation(value = "取消订单")
    @PostMapping(value = "/cancel", produces = "application/json; charset=UTF-8")
    public R<Object> cancel(
            @ApiParam(value = "公司uid") @RequestParam(value = "corpUid") String corpUid,
            @ApiParam(value = "门店uid") @RequestParam(value = "storeUid") String storeUid,
            @ApiParam(value = "门店名称") @RequestParam(value = "storeName") String storeName,
            @ApiParam(value = "员工uid") @RequestParam(value = "staffUid") String staffUid,
            @ApiParam(value = "员工名") @RequestParam(value = "staffName") String staffName,
            @ApiParam(value = "订单号") @RequestParam(value = "code") String code,
            @ApiParam(value = "备注") @RequestParam(value = "remark", required = false) String remark
    ) {

        return orderFormServiceV5.cancel(storeUid, staffUid, staffName, code, remark);
    }


    @ApiOperation(value = "修改送货地址")
    @PostMapping(value = "/editAddress", produces = "application/json; charset=UTF-8")
    public R<Object> editAddress(
            @ApiParam(value = "公司uid") @RequestParam(value = "corpUid") String corpUid,
            @ApiParam(value = "门店uid") @RequestParam(value = "storeUid") String storeUid,
            @ApiParam(value = "门店名称") @RequestParam(value = "storeName") String storeName,
            @ApiParam(value = "员工uid") @RequestParam(value = "staffUid") String staffUid,
            @ApiParam(value = "员工名") @RequestParam(value = "staffName") String staffName,
            @ApiParam(value = "订单号") @RequestParam(value = "code") String code,
            @ApiParam(value = "送货地址id") @RequestParam(value = "deliveryId") Long deliveryId
    ) {
        return orderFormServiceV5.editAddress(storeUid, staffUid, code, deliveryId);
    }


    @ApiOperation(value = "删除")
    @PostMapping(value = "/delete", produces = "application/json; charset=UTF-8")
    public R<Object> delete(
            @ApiParam(value = "公司uid") @RequestParam(value = "corpUid") String corpUid,
            @ApiParam(value = "门店uid") @RequestParam(value = "storeUid") String storeUid,
            @ApiParam(value = "门店名称") @RequestParam(value = "storeName") String storeName,
            @ApiParam(value = "员工uid") @RequestParam(value = "staffUid") String staffUid,
            @ApiParam(value = "员工名") @RequestParam(value = "staffName") String staffName,
            @ApiParam(value = "订单号") @RequestParam(value = "code") String code
    ) {
        return orderFormServiceV5.deleteForm(storeUid, staffUid, code);
    }


    @ApiOperation(value = "重新加入购物车")
    @PostMapping(value = "/againAddShopCart", produces = "application/json; charset=UTF-8")
    public R<Object> againAddShopCart(
            @ApiParam(value = "公司uid") @RequestParam(value = "corpUid") String corpUid,
            @ApiParam(value = "门店uid") @RequestParam(value = "storeUid") String storeUid,
            @ApiParam(value = "门店名称") @RequestParam(value = "storeName") String storeName,
            @ApiParam(value = "员工uid") @RequestParam(value = "staffUid") String staffUid,
            @ApiParam(value = "员工名") @RequestParam(value = "staffName") String staffName,
            @ApiParam(value = "订单号") @RequestParam(value = "code") String code
    ) {
        return orderFormServiceV5.againAddShopCart(storeUid, staffUid, staffName, code);
    }


    @ApiOperation(value = "银行转账，上传银行转账截图")
    @PostMapping(value = "/uploadBankPayImg", produces = "application/json; charset=UTF-8")
    public R<Object> uploadBankPayImg(
            @ApiParam(value = "公司uid") @RequestParam(value = "corpUid") String corpUid,
            @ApiParam(value = "门店uid") @RequestParam(value = "storeUid") String storeUid,
            @ApiParam(value = "门店名称") @RequestParam(value = "storeName") String storeName,
            @ApiParam(value = "员工uid") @RequestParam(value = "staffUid") String staffUid,
            @ApiParam(value = "员工名") @RequestParam(value = "staffName") String staffName,
            @ApiParam(value = "订单号") @RequestParam(value = "code") String code,
            @ApiParam(value = "图片文件") @RequestPart(value = "file") MultipartFile file
    ) throws Exception {
        return orderFormServiceV5.uploadBankPayImg(storeUid, staffUid, staffName, code, file);
    }


    @ApiOperation(value = "删除订单的银行转账截图")
    @PostMapping(value = "/dropBankPayImg", produces = "application/json; charset=UTF-8")
    public R<Object> dropBankPayImg(
            @ApiParam(value = "公司uid") @RequestParam(value = "corpUid") String corpUid,
            @ApiParam(value = "门店uid") @RequestParam(value = "storeUid") String storeUid,
            @ApiParam(value = "门店名称") @RequestParam(value = "storeName") String storeName,
            @ApiParam(value = "员工uid") @RequestParam(value = "staffUid") String staffUid,
            @ApiParam(value = "员工名") @RequestParam(value = "staffName") String staffName,
            @ApiParam(value = "订单号") @RequestParam(value = "code") String code,
            @ApiParam(value = "图片id") @RequestParam(value = "imgId") Long imgId
    ) {
        return orderFormServiceV5.dropBankPayImg(storeUid, staffUid, code, imgId);
    }


    @ApiOperation(value = "获取订单的银行转账截图")
    @PostMapping(value = "/getBankPayImg", produces = "application/json; charset=UTF-8")
    public R<Object> getBankPayImg(
            @ApiParam(value = "公司uid") @RequestParam(value = "corpUid") String corpUid,
            @ApiParam(value = "门店uid") @RequestParam(value = "storeUid") String storeUid,
            @ApiParam(value = "门店名称") @RequestParam(value = "storeName") String storeName,
            @ApiParam(value = "员工uid") @RequestParam(value = "staffUid") String staffUid,
            @ApiParam(value = "员工名") @RequestParam(value = "staffName") String staffName,
            @ApiParam(value = "订单号") @RequestParam(value = "code") String code
    ) {
        return orderFormServiceV5.getBankPayImg(storeUid, staffUid, code);
    }


    @ApiOperation(value = "申请银行转账")
    @PostMapping(value = "/bankPay", produces = "application/json; charset=UTF-8")
    public R<Object> bankPay(
            HttpServletRequest request,
            @ApiParam(value = "公司uid") @RequestParam(value = "corpUid") String corpUid,
            @ApiParam(value = "门店uid") @RequestParam(value = "storeUid") String storeUid,
            @ApiParam(value = "门店名称") @RequestParam(value = "storeName") String storeName,
            @ApiParam(value = "员工uid") @RequestParam(value = "staffUid") String staffUid,
            @ApiParam(value = "员工名") @RequestParam(value = "staffName") String staffName,
            @ApiParam(value = "订单号") @RequestParam(value = "code") String code
    ) throws Exception {
        return orderFormServiceV5.bankPay(request, storeUid, staffUid,staffName, code);
    }

    @ApiOperation(value = "取消银行转账")
    @PostMapping(value = "/cancelBankPay", produces = "application/json; charset=UTF-8")
    public R<Object> cancelBankPay(
            @ApiParam(value = "公司uid") @RequestParam(value = "corpUid") String corpUid,
            @ApiParam(value = "门店uid") @RequestParam(value = "storeUid") String storeUid,
            @ApiParam(value = "门店名称") @RequestParam(value = "storeName") String storeName,
            @ApiParam(value = "员工uid") @RequestParam(value = "staffUid") String staffUid,
            @ApiParam(value = "员工名") @RequestParam(value = "staffName") String staffName,
            @ApiParam(value = "订单号") @RequestParam(value = "code") String code
    ) {
        return orderFormServiceV5.cancelBankPay(storeUid, staffUid, staffName,code);
    }

}
